package cn.admobiletop.adsuyi.adapter.gdt.util;

import android.annotation.SuppressLint;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;

import cn.admobiletop.adsuyi.ADSuyiSdk;
import cn.admobiletop.adsuyi.config.ADSuyiInitConfig;

/**
 * @author ciba
 * @description 描述
 * @date 2020/9/10
 */
public class NetWorkUtil {

    @SuppressLint("MissingPermission")
    public static boolean isWifi() {
        ADSuyiInitConfig config = ADSuyiSdk.getInstance().getConfig();
        if (config == null || config.isCanUseWifiState()) {
            try {
                ConnectivityManager connectivityManager = (ConnectivityManager) ADSuyiSdk.getInstance().getContext()
                        .getSystemService(Context.CONNECTIVITY_SERVICE);
                NetworkInfo info = connectivityManager == null ? null : connectivityManager.getActiveNetworkInfo();
                return info != null && ConnectivityManager.TYPE_WIFI == info.getType();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return false;
    }
}
